

//
//  DiscoverHelper.m
//  Router
//
//  Created by teki on 15/10/26.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "DiscoverHelper.h"
#import "routerIPHelper.h"

@implementation DiscoverHelper
- (void)discoverWIFISuccess:(RequestSussess)success failure:(RequestFailure)failure
{
    NSURL *url  = [NSURL URLWithString:DISCOVER_WIFI_POST_URL];
    NSLog(@"url:%@",DISCOVER_WIFI_POST_URL);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    request.timeoutInterval = 5.0f;  /// 设置他的超时时间  
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if (data)
        {
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                success(YES,dict,nil);
            });
        }
        else{
            dispatch_async(dispatch_get_main_queue(), ^{
                failure(connectionError);
            });
        }
    }];
}



- (void)getWIFIBindDeviceWithDeviceID:(NSString *)deviceID success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSDictionary *param  = @{@"deviceID":deviceID};
    [self.requestOperator requestPostWithURL:DISCOVER_WIFI_BIND_DEVICE_POST_URL params:param success:^(BOOL succ, id responseObject) {
        success(YES,responseObject,nil);
    } failure:failure];
}



- (void)checkBroadBandConfigWithPPPOEName:(NSString *)pppoeName pppoePassword:(NSString *)pppoePassword success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSDictionary *param = @{@"pppoeName":pppoeName,
                            @"pppoePassword":pppoePassword};
    [self.requestOperator requestPostWithURL:DISCOVE_SETTING_PPPOE_POST_URL params:param success:^(BOOL succ, id responseObject) {
        success(YES,responseObject,nil);
    } failure:failure];
    
//    NSURL *url  = [NSURL URLWithString:DISCOVER_WIFI_POST_URL];
//    NSLog(@"url:%@",DISCOVER_WIFI_POST_URL);
//    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//    request.timeoutInterval = 5.0f;  /// 设置他的超时时间
//    NSString *postString = [NSString stringWithFormat:@"pppoeName=%@pppoePassword=%@",pppoeName,pppoePassword];
//    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
//        if (data)
//        {
//            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                success(YES,dict,nil);
//            });
//        }
//        else{
//            dispatch_async(dispatch_get_main_queue(), ^{
//                failure(connectionError);
//            });
//        }
//    }];

}


- (void)checkIPConfigWithIPaddress:(NSString *)IPaddr mask:(NSString *)mask gatewayaddr:(NSString *)gatewayAddr dnsaddress:(NSString *)DNS dnsbakaddress:(NSString *)DNSBackupAddr success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSDictionary *param  =@{@"ipaddr":IPaddr,
                            @"mask":mask,
                            @"gatewayaddr":gatewayAddr,
                            @"dnsaddr":DNS,
                            @"dnsbakaddr":DNSBackupAddr};
    [self.requestOperator requestPostWithURL:DISCOVE_SETTITNG_IP_POST_URL params:param success:^(BOOL succ, id responseObject) {
        success(YES,responseObject,nil);
    } failure:failure];
}



- (void)bindUserAndDeviceWithDeviceID:(NSString *)deviceID User:(NSString *)user SSID:(NSString *)SSID success:(RequestSussess)success failure:(RequestFailure)failure
{
    NSDictionary *param = @{@"deviceID":deviceID,
                            @"user":user,
                            @"ssid":SSID};
    [self.requestOperator requestPostWithURL:DISCOVER_BIND_USER_AND_DEVICE_POST_URL params:param success:^(BOOL succ, id responseObject) {
        success(YES,responseObject,nil);
    } failure:failure];
}
@end
